#pragma once

#define SEL_CHA_ONLINE_WHERE1 "select channel from online where "\
                              "conference='%s';"
#define SEL_CHA_ONLINE_ALL    "select channel from online;"

#define SEL_CHA_ONLINE_WHERE2 "select channel from online where "\
                              "conference='%s' and talking='1';"

#define SEL_CHA_ONLINE_WHERE3 "select channel from online where "\
                              "talking='1';"

#define SEL_CHA_ONLINE_WHERE4 "select channel from online where "\
                              "number_id='0';"

#define SEL_CHA_ONLINE_WHERE5 "select channel from online where "\
                              "conference=\'%s\' and channel like \'%%%s%%\';"

#define SEL_CHA_ONLINE_WHERE6 "select channel from online where "\
                              "number=\'%s\';"

#define UPD_ONLINE_WHERE1     "update online set lasttalk='%s', onconf='1' "\
                              "where conference='%s' and channel not like "\
                              "'%%%s%%';"

#define UPD_ONLINE_WHERE2     "update online set state = '%d' "\
                              "where channel = '%s';"

#define SEL_CONF_ONLINE_WHERE1 "select conference,lasttalk from online where "\
                               "onconf='%d' state='1';"

#define SEL_CNT_ONLINE_WHERE1  "select count(*) from online where "\
                               "conference='%s' and number='100';"

typedef struct _counsellor_info
{
   char mLastTime[24];
   char mCounsellorName[64];
}COUNSELLORINFO;

typedef struct _online
{
   int   mId;
   int   mMemberId;
   char  mConference[64];
   char  mChannel[64];
   int   mTalking;
   int   mMuted;
   char  mNumber[32];
   char  mName[32];
   int   mAdmin;
   char  mUniqueId[32];
   char	 mState[20];
}ONLINE;

typedef struct _cdr
{
   time_t calldate;
   char   clid[80];
   char   src[80];
   char   dst[80];
   char   context[80];
   char   channel[80];
   char   dstchannel[80];
   char   lastapp[80];
   char   lastdata[80];
   int    duration;
   int    billsec;
   char   disposition[80];
   int    amaflags;
   char   userfield[255];
   char   accountcode[80];
   char   uniqueid[32];
   time_t leavetime;
}CDR;

int online_sql_disconnect();

int online_sql_connect();

int online_sql_get( ONLINE * aOnline );

int online_sql_set_confjoin( ONLINE * aOnline );

int online_sql_set_confstate( char * aState, char * aChannel );

int online_sql_del_conf( char * aConference,
                         char * aChannel,
                         int    aMember );

int online_sql_get_channellist( char * aConfName,
                                char   aChannel[][64],
                                int  * aCount,
                                int    aAll);

int online_sql_get_counsellorlist( int    aOnconf,
                                   int    aReadyTimeVal,
                                   char   aChannel[][64],
                                   int  * aCount);

int online_sql_get_counsellor( char * aConfName,
                               char * aChannel,
                               int    aChLen );

int online_sql_get_customer( char * aConfName,
                             char * aOutChannel,
                             char * aChannelBufPtr,
                             int    aChannelBufLen );

int online_sql_set_lasttalk( char * aConfName,
                             char * aOutChanName );
int online_sql_set_channelstate( char * aChannel,
                                 int    aState );

int online_sql_set_onconf( char * aConfName,
                           bool   aOnConf );

int online_sql_get_channel_by_callid( char *  aMemberNumPtr,
                                      char * aChannelBufPtr,
                                      int  * aChannelBufLen );
